home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / BTSETBUF.C < prev    next >
Text File  |  1991-09-23  |  2KB  |  94 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)btsetbuf.c    1.5 - 91/09/23" */
  5.  
  6. #include <ansi.h>
  7.  
  8. /* ansi headers */
  9. #include <errno.h>
  10.  
  11. /* library headers */
  12. #include <blkio.h>
  13.  
  14. /* local headers */
  15. #include "btree_.h"
  16.  
  17. /*man---------------------------------------------------------------------------
  18. NAME
  19.      btsetbuf - assign buffering to a btree
  20.  
  21. SYNOPSIS
  22.      #include <btree.h>
  23.  
  24.      int btsetbuf(btp, buf)
  25.      btree_t *btp;
  26.      void *buf;
  27.  
  28. DESCRIPTION
  29.      The btsetbuf function causes the storage area pointed to by buf
  30.      to be used by the btree associated with btree pointer btp instead
  31.      of an automatically allocated buffer area.  If buf is the NULL
  32.      pointer, btp will be completely unbuffered.
  33.  
  34.      The size of the storage area needed can be obtained using the
  35.      BTBUFSIZE() macro:
  36.  
  37.           char buf[BTBUFSIZE(M, KEYSIZE, BTBUFCNT)];
  38.           btsetbuf(btp, buf);
  39.  
  40.      where M is the degree of the btree, KEYSIZE is the size of the
  41.      keys int the btree, and BTBUFCNT is the default number of nodes
  42.      buffered when a btree is opened.  BTBUFCNT is defined in
  43.      <btree.h>.  If the number of nodes buffered has been changed using
  44.      btsetvbuf, then that number should be used in place of BTBUFCNT.
  45.  
  46.      btsetbuf may be called at any time after opening the btree,
  47.      before and after it is read or written; the buffers are flushed
  48.      before installing the new buffer area.
  49.  
  50.      btsetbuf will fail if one or more of the following is true:
  51.  
  52.      [EINVAL]       btp is not a valid btree pointer.
  53.      [BTENBUF]      buf is not the NULL pointer and btp
  54.                     is not buffered.
  55.      [BTENOPEN]     btp is not open.
  56.  
  57. SEE ALSO
  58.      btsetvbuf, btsync.
  59.  
  60. DIAGNOSTICS
  61.      Upon successful completion, a value of 0 is returned.  Otherwise,
  62.      a value of -1 is returned, and errno set to indicate the error.
  63.  
  64. ------------------------------------------------------------------------------*/
  65. #ifdef AC_PROTO
  66. int btsetbuf(btree_t *btp, void *buf)
  67. #else
  68. int btsetbuf(btp, buf)
  69. btree_t *btp;
  70. void *buf;
  71. #endif
  72. {
  73.     /* validate arguments */
  74.     if (!bt_valid(btp)) {
  75.         errno = EINVAL;
  76.         return -1;
  77.     }
  78.  
  79.     /* check if not open */
  80.     if (!(btp->flags & BTOPEN)) {
  81.         errno = BTENOPEN;
  82.         return -1;
  83.     }
  84.  
  85.     /* set buffering */
  86.     if (bsetbuf(btp->bp, buf) == -1) {
  87.         if (errno == BENBUF) errno = BTENBUF;
  88.         BTEPRINT;
  89.         return -1;
  90.     }
  91.  
  92.     return 0;
  93. }
  94.